<!DOCTYPE html>
<!--在html页面中引入thymeleaf命名空间，即，此时在html模板文件中动态的属性使用th:命名空间修饰 。-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>ADD</title>
    <link rel="stylesheet" type="text/css" href="../static/layui-v2.6.13/layui/css/layui.css">
    <script type="text/javascript" src="../static/js/jquery.min-2.1.1.js"></script>
    <script type="text/javascript" src="../static/layui-v2.6.13/layui/layui.js"></script>

</head>
<body>
<div>
    <form class="layui-form" id="selectForm">
        <div class="div1">
            <div class="layui-inline">
                <input type="text" id="majorName" name="majorName" class="layui-input" placeholder="商品名称">
        </div>
    </div>
</form>
    <br>
    <button type="submit" class="layui-btn layui-btn-radius layui-btn-primary" onclick="sel()" >查询</button>
    <button type="submit" class="layui-btn layui-btn-radius layui-btn-primary" onclick="add()">添加</button>
</div>
<table class="layui-table">
<thead>
<tr>
    <th>id</th>
    <th>专业名</th>
    <th>学院id</th>
    <th>专业id</th>
    <th>操作</th>
</tr>

</thead>
<tr th:each = "s:${list}">
    <td th:text="${s.id}"></td>
    <td th:text="${s.majorName}"></td>
    <td th:text="${s.collegeId}"></td>
    <td th:text="${s.majorId}"></td>
    <td>
        <button class="layui-btn layui-btn-primary layui-btn-radius" onclick="update(${s.id})">更新</button>
        <button class="layui-btn layui-btn-primary layui-btn-radius" th:value="${s.id}" onclick="del(this.value)">删除</button>
    </td>
<tr>

</table>
div>
<button th:onclick="jumpPage(1)">首页</button>
<button th:onclick="jumpPage([[${pageNo - 1}]])">上一页</button>
<span th:text="${pageNo} + '/' + ${pageCount} + '页' "></span>
<button th:onclick="jumpPage([[${pageNo + 1}]])">下一页</button>
<button th:onclick="jumpPage([[${pageCount}]])">尾页</button>
</div>
</body>
<script>
    //分页
    function jumpPage(pageNo){
        if(pageNo < 1){
            pageNo = 1;
        }
        var params = $("form").serialize();
        window.location.href = "index?pageNo="+pageNo+"&"+params;
    }
</script>
<script>
    function sel(){
        console.info("11111");
        var majorName = $("#majorName").val();
        window.location.href="index?majorName="+majorName;

    }
    function add(){
        layer.open({
            type:2,
            content:'add',
            area:['500px','300px']
        })
    }
</script>
<script>
    function del(id){

        var params = "id="+id;
        $.ajax({
            url: "del",
            data: params,
            type: "post",
            success: function (str) {
                if (str == "1") {

                alert("删除成功");
                parent.location.reload();
            } else {
                    alert("删除失败");
                }
              }
        })
    }
</script>
</html>